<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
    <title>设备状态</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">设备状态</a>
</header>
<!-- header end -->

<div class="page home_page">
    <!-- 远程补币 -->
    <div class="home_ycbb">
        <em>远程补币</em>
        <div class="home_addremove">
            <form id="addform">
            <a href="JavaScript:;" class='home_removebutton'>-</a>
                <input type="text" name="coin" id="coin" value="1">
            <a href="JavaScript:;" class='home_addbutton'>+</a>
            </form>
        </div>
        <div ${device.state ==1?"style='display:'":"style='display:none'"} class="home_bbuttom"><a href="JavaScript:;" id="addSubBtn">确认</a></div>
    </div>
    <!-- 远程补币 end -->
    <div class="home_sbzt">
        <ul>
            <li><a href="${basePath}wechat/operate/device/${device.deviceId}/qrCodeView"><span>二维码</span></a></li>
            <li><a href="${basePath}wechat/operate/device/${device.deviceId}/discountView"><span>套餐设置</span></a></li>
            <li><a href="JavaScript:;" class='sbzt_name'><span>设备名称</span><i>${device.deviceName}</i></a></li>
            <li><div><span>是否在线</span><i>${device.state ==1?'在线':'离线'}</i></div></li>
            <li>
                <div>
                    <span>禁用/启动</span>
                    <div class="home_ztkg ${device.isOnline==1?'cur':''}"><i></i></div>
                </div>
            </li>
            <li><div><span>场地归属</span><i>${device.address}</i></div></li>
            <li><div><span>设备简码</span><i>${device.deviceShortCode}</i></div></li>
            <li><div><span>唯一码</span><i>${device.imme}</i></div></li>
        </ul>
    </div>
</div>

<!-- 设备名称弹窗 -->
<div class="home_sbnamepop ty_pop">
    <div class="popbg"></div>
    <div class="sbname_inner">
        <em>设备名称</em>
        <p><input type="text" class="equipmentName" value="${device.deviceName}"/></p>
        <div><a href="JavaScript:;">取消</a><a href="JavaScript:;">确定</a></div>
    </div>
</div>
<!-- 设备名称弹窗 end -->
</body>

<script type="application/javascript">
    //限制远程补币输入框长度、类型
    $("#coin").long({"element":"#coin","action":"keyup","stringl":"1","stringls":"3","reg":/^[123456789]\d{0,5}$/, "stavalue":"1"});
    //限制设备名称输入框长度、类型
    $(".equipmentName").long({"element":".equipmentName","action":"keyup","stringl":"1","stringls":"8","reg":/^.{0,20}$/, "stavalue":"设备1"});


    function View(){
        var that = this;

        that.events = [
            { sel : '#addSubBtn', act : 'click', func : 'addSub' },
            { sel : '.home_ztkg', act:'click', func:'changeSub' }
        ];

        that.addSub = function(){
            $.ajax({
                url:'${basePath}wechat/operate/device/${device.deviceId}/addCoin',
                type : 'POST',
                data : {'coin':$("#coin").val()},
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        alert(ret.info);
                        window.location = "${basePath}wechat/operate/device/${device.deviceId}/showView";
                    }else{
                        alert(ret.info);
                    }
                }
            });
        };

        that.changeSub = function(){
            var online = '${device.isOnline}';
            if(online == '1'){
                online = '2';
            }else{
                online = '1';
            }
            $.ajax({
                url:'${basePath}wechat/operate/device/${device.deviceId}/edit',
                type : 'POST',
                data : {'isOnline':online},
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        window.location = "${basePath}wechat/operate/device/${device.deviceId}/showView";
                    }else{
                        alert(ret.info);
                    }
                }
            });
        };

        EventHandler.call(that, that.events);

        return that;
    }

    var view;

    $(function(){
        inherit(View, EventHandler);
        view = new View();
    });

    $(".sbname_inner div a").eq(1).on("click" , function(){
        var deviceName = $(".sbname_inner p input").val();
        $.ajax({
            url:'${basePath}wechat/operate/device/${device.deviceId}/editName',
            type : 'POST',
            data : {"deviceName":deviceName},
            error: function (response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function (ret) {
                if(ret.result) {
                    $(".sbzt_name i").text(deviceName);
                }else{
                    alert(ret.info);
                }
            }
        });
    });

</script>


</html>